package learn.ch1;

/**
 * @Description todo
 * @Author yusj
 * @Date 2021/12/11
 * @Version 1.0
 */
public class TsThread extends Thread{
    @Override
    public void run() {
        try {
            while(!isInterrupted()){
                Thread.sleep(1000);
                System.out.println("sssssss"+Thread.currentThread().getId());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
            //出现interrupt  异常需要自己终止一下。
            interrupt();
        }
    }

    public static void main(String[] args) {
        TsThread tsThread=new TsThread();
        TsThread tsThread1=new TsThread();
        tsThread1.start();
        tsThread.start();
        try {
            Thread.sleep(10000);
            tsThread1.interrupt();
            tsThread.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
